#include "test.h"
#include <position.h>
#include <string.h>


static int test_clear()
{
  position_t pos;
  memset(&pos, sizeof(pos), 'X');
  position_clear(&pos);
  TEST_ASSERT(position_get_stm(&pos) == WHITE);
  TEST_ASSERT(pos.bb_colors[WHITE] == 0);
  TEST_ASSERT(pos.bb_colors[BLACK] == 0);
  for (int s = 0; s < 2; s++)
    for (int p = PAWN; p <= KING; p += 2)  // !!!!
      TEST_ASSERT(BB_POS_PIECES(pos, s, p);
  TEST_ASSERT(position_get_ep_square(&pos) == NO_ENPASSANT);
  TEST_ASSERT(position_get_castling_caps(&pos) == 
	      (WCASTLE_SHORT | WCASTLE_LONG | BCASTLE_SHORT | BCASTLE_LONG));
  TEST_ASSERT(position_get_half_moves(&pos) == 0);
  TEST_ASSERT(position_get_full_moves(&pos) == 1);
  return 1;
}


static int test_drop()
{
  position_t pos;
  position_clear(&pos);

  int p = 0;
  
  for (int i = 0; i < 64; i++) {
    position_drop_piece(&pos, i , p);
    TEST_ASSERT(position_get_square(&pos, i) == p);
    p++;
    if (p == EMPTY || p == WKING || p == BKING)
      p = 0;
  }
  return 1;
}


void test_position()
{
  RUN_TEST("POS_CLEAR", test_clear);
  RUN_TEST("POS_DROP", test_drop);
}
